package pers.wensheng.patterns.behavioral_pattern.memento_pattern.black_box;

import lombok.Data;
import lombok.Getter;
import lombok.Setter;

/**
 * 游戏角色
 */
@Data
public class GameRole {
    private int vit; //生命力
    private int atk; //攻击力
    private int def; //防御力

    /**
     * 初始状态
     */
    public void initState(){
        this.vit = 100;
        this.atk = 100;
        this.def = 100;
    }

    /**
     * 战斗以后
     */
    public void fight(){
        this.vit = 0;
        this.atk = 0;
        this.def = 0;
    }

    /**
     * 保存角色状态
     */
    public Memento saveState(){
        return new RoleStateMemento(vit,atk,def);
    }

    /**
     * 恢复角色状态
     * @param memento
     */
    public void recoverState(Memento memento){
        RoleStateMemento roleStateMemento = (RoleStateMemento) memento;
        this.vit = roleStateMemento.getVit();
        this.atk = roleStateMemento.getAtk();
        this.def = roleStateMemento.getDef();
    }


    /**
     * 备忘录类，私有的
     */
    @Getter
    @Setter
    private class RoleStateMemento implements Memento {
        private int vit; //生命力
        private int atk; //攻击力
        private int def; //防御力

        public RoleStateMemento(int vit, int atk, int def) {
            this.vit = vit;
            this.atk = atk;
            this.def = def;
        }
    }
}
